package com.ck.file.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ck
 * @date 2023/8/25 10:52
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${file.prefix}")
    private String prefix;
    @Value("${file.upLoadPath}")
    private String localFilePath;

    /**
     * 自定义一个的资源处理器 实现 资源映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        WebMvcConfigurer.super.addResourceHandlers(registry);
        registry.addResourceHandler(prefix+"/**") //虚拟路径
                .addResourceLocations("file:"+localFilePath+"/"); //绝对路径
    }
}
